function D(settings){
    var _settings = settings || {};
    this.title = _settings.title || "对话框";
    this.width = _settings.width || 460;
    this.height = _settings.height || 0;
    this.doOkFunctionName = _settings.doOkFunctionName || "doOk";
    var id_suffix = Math.ceil(Math.random()*1000000);
    this.loadedContent = false;//是否已加载内容
    //初始化对话框
    this.did = "_d_"+id_suffix;
    this.$d = $("<div id=\""+this.did+"\" class=\"dialog\" style=\"display:none;width:480px;\">" +
        "<span class=\"dialogTitle\"><span>"+this.title+"</span><a href=\"javascript:void(0);\"></a></span>" +
        "<div class=\"d_loading\">正加加载数据...</div>" +
        "<div class=\"d_content\"></div>" +
        "<div class=\"toolbar2\"><button class='ok'>确定</button><button class='cancel'>取消</button></div>"+
        "</div>");
    this.$d.appendTo("body");
    var _instance = this;
    //为对话框增加移动事件
    this.$d.find(".dialogTitle").mousedown(function (e) { //e鼠标事件
        var offset = _instance.$d.offset(); //DIV在页面的位置
        var x = e.pageX - offset.left; //获得鼠标指针离DIV元素左边界的距离
        var y = e.pageY - offset.top; //获得鼠标指针离DIV元素上边界的距离
        $(document).bind("mousemove", function (ev)//绑定鼠标的移动事件，因为光标在DIV元素外面也要有效果，所以要用doucment的事件，而不用DIV元素的事件
        {
            _instance.$d.stop(); //加上这个之后
            var _x = ev.pageX - x; //获得X轴方向移动的值
            var _y = ev.pageY - y; //获得Y轴方向移动的值
            _instance.$d.animate({ left: _x + "px", top: _y + "px" }, 10);
        });
    });
    $(document).mouseup(function () {
        $(this).unbind("mousemove");
    });
    this.$d.find(".dialogTitle a").click(function(){
        _instance.close();
    });
    this.$d.find(".cancel").click(function(){
        _instance.close();
    });
    var css = {/*"width":this.width+"px"*/};
    if(this.height>0){
        css.height = this.height+"px";
        css.overflowY = "auto";
    }
    this.$d.css(css);
};
D.prototype.show = function(url,data,okHandler,loadedHandler){
    if(typeof url !== "string" && url.length==0){
        alert("系统对话框显示时必须指定url参数来获取对话框数据,请确定.");
        return;
    }
    var $d = $("#_f_dialog");
    var zIndex = $d.css("zIndex");
    zIndex = parseInt(zIndex);
    if(isNaN(zIndex)){
        zIndex = 1;
    }
    this.$d.css("zIndex", zIndex+1);
    //给确定按钮附加事件
    var _instance = this;
    var okBtn = this.$d.find(".ok");
    if(typeof okHandler === "function"){
        okBtn.css("display","");
        okBtn.unbind();
        okBtn.click(function(){
            var ret = eval("("+_instance.doOkFunctionName+"())");
            if(ret){
                var r = okHandler(ret);
                if(typeof r == "undefined" || r){
                    _instance.close();
                }
            }
        });
    }else{
        okBtn.css("display","none");
    }
    var _url = Http.getUrl(url,data);
    if(typeof this.url === "undefined" || _url != this.url){
        this.url = _url;
        this.$d.find(".d_loading").css("display","block");
        //从url中加载数据,并装载到内容区域中
        Http.doGetHtml(_url,null,function(html){
            _instance.$d.find(".d_content").html(html);
            _instance.$d.find(".d_loading").css("display","none");
            if(typeof loadedHandler === "function"){
                loadedHandler();
            }
        });
    }
    //重新定位并显示对话框
    var ww=$(document).width();
    var dw=this.$d.width();
    this.x= this.x-dw/2;
    if (this.x<0) this.x=10;
    if ((this.x+dw)>ww) this.x=ww-dw-20;
    this.$d.css({"display":"block","left": this.x+"px","top": this.y+"px"});
};
D.prototype.close = function(){
    this.$d.hide();
};
D.prototype.resetXY = function(sender){
    var xy = $(sender).offset();
    this.x = xy.left;
    this.y = xy.top;
};